//
//  WCNServiceRecordVC.m
//  WCN
//
//  Created by 杨鑫 on 15/7/8.
//  Copyright (c) 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNServiceRecordVC.h"
//
#import "WCNSysDetailTCell.h"
//
#import "Macros.h"
#import "Constants.h"

@interface WCNServiceRecordVC ()<UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSArray *serviceArray;

@end

@implementation WCNServiceRecordVC

- (instancetype)initWithArray:(NSArray *)serviceArray
{
    self = [super init];
    if (self) {
        _serviceArray = serviceArray;
    }
    return self;
}

- (void)loadView
{
    [super loadView];
    
    self.title = @"服务记录";
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-kNavHeight) style:UITableViewStyleGrouped];
    self.tableView = tableView;
    tableView.backgroundColor = kAppBg;
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15)];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.rowHeight = 44.0;
    [self.view addSubview:tableView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.tableView registerClass:[WCNSysDetailTCell class] forCellReuseIdentifier:@"WCNSysDetailTCell"];
}

#pragma mark - <UITableViewDataSource, UITableViewDelegate>

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WCNSysDetailTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WCNSysDetailTCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSDictionary *item = self.serviceArray[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", item[@"apptDate"], item[@"timePeriod"]];
    NSString *statusStr = item[@"apptStatusName"];
    cell.detailTextLabel.text = statusStr;
    if ([statusStr isEqualToString:@"已完成"]) {
        cell.detailTextLabel.textColor = [UIColor darkGrayColor];
    } else {
        cell.detailTextLabel.textColor = HexRGB(0x01b8a3);
    }
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.serviceArray.count;
}

@end
